import requests, json, datetime


def get_session_data():
    today = datetime.datetime.now().strftime("%Y-%m-%d")
    loginurl = 'https://auth.xincheng.com/LoginService.ashx'
    listurl = 'http://passport.pri.xincheng.com/subsystems.do'
    logindata = {
        'lang': 'en - us',
        'systemCode': 'A07',
        'rememberPassword': 'false',
        'challengeNumber': '',
        'randomDate': '2021-05-23',
        '15': '34:50',
        'hidetxtPassword': 'lU/Q3OulShPF0iazGNk5O7YGzt9cMlFGiz5l/m73bCJ9WSVGCtqmnHroP6IjSat4m7HTQlMn9VGVbAssdYyR4BOsEdjB3lTY4wmzqd8gfwV5YpbaeoERAzuwpl7QzCyjEnV34Nu7eMlyXZrJLxdGLEdVxdKetMMhJlT2y5sKL1SrpPW4i5sJRC2uH2Jh2qeWkOEW87C8QF9Tyr+Hhyx8ZjH0RbtKW82gLG+edUxls2nXZ6rMkZHmOh9QrPc2/ORlIYAHItYHyd098/6+afAQavKHcmh8kGmmNW0uZYOs57ZJxwLpJ2NoDOX+YWgS57Wh6ceQXqZR3Gt7b+dDN7M1gw==',
        'txtIsTrustAccessor': 'True',
        'txtUserName': 'wangrui20',
    }
    loginheader = {
        'Referer': 'https://auth.xincheng.com/?challengeNumber=ZGY5eGpsaGt5NTB0cWRlcHJ0c2h1OXVuMDBlMHFnbXMwN2JmZGEzYmEyNTlsaHFtYXN5MHlheWRjOGNsZmIyZjF4ejJ0b3BvbW1mMHl4ZTR4b2ZlcnlrdGVsemRncG1yY3MybzVicmxyOHlqdDRsbTgzb2I5d2tpOGx3dnlvMW9zOXJ6azh4OWRoYnVkd253b2pubHNpbmN2Y3ZvOWttNjBtcW14MWV2NDFnOHpmc2s4bHN2ZmN3aGk0Y2RhZXR4c2JtbjJmYmZ6cWV1MWlibnE2OGUyOTd4azBpMGd5ODlrMmFqM2w3djMxb2d5c3N1bnFnYWFjNHV6YWluZWY5cA==&flag=3&systemCode=A07&RetutnUrl=http%3A%2F%2Fekp.xincheng.com%2Fsys%2Fportal%2Fpage.jsp',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
    }
    session = requests.session()
    session.post(loginurl, data=logindata, headers=loginheader)
    tokenreq = session.get(listurl)
    tokenreq.content.decode()
    tokenreq = json.loads(tokenreq.text)
    tokenreq = tokenreq['body']['user']['orgId']
    return tokenreq, session


def get_thisnulldatashop():
    today = datetime.datetime.now()
    oneday = datetime.timedelta(days=1)
    yesterday = (today - oneday).strftime("%Y/%m/%d")
    token = get_session_data()[0]
    session = get_session_data()[1]
    url = "http://databiapi.web.pri.xincheng.com/shop/shopAnalyze/getShopEntitySaleInfo?token=misUser" + token
    header = {
        'User-Agent': 'Mozilla/5.0(Macintosh;IntelMacOSX10_15_6) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 84.0.4147.89Safari / 537.36',
        'Referer': 'http://databi.pri.xincheng.com/',
    }
    data = {
        'floors': '',
        'from': str(yesterday),
        'to': str(yesterday),
        'pageIndex': '1',
        'pageSize': '200',
        'shopTypes': '',
        'type': '0',
        'shopEntityIds': '',
        'id': get_session_data(),
        'orderKey': 'saleAmount',
        'orderBy': 'desc',
        'terminalStatus': '1',
        'deviationCheck': '',
        'effectiveTerminalFlag': '',
    }
    req = session.post(url, data=data, headers=header)
    req.content.decode()
    data = json.loads(req.text)
    data = data['data']['data']
    shopname = []
    for i in data:
        money = i["recommendAmount"]
        shangbao = i['claimMoneyTotal']
        if money == 0 and shangbao != 0:
            shopname.append(i['entityName'])
    return shopname
